class Subject {
    constructor() {
        this.observers = []
    }

    add(observer) {
        this.observers.push(observer)
    }

    remove(observe) {
        this.observers = this.observers.filter(observer => observer !== observe)
    }

    notify() {
        this.observers.forEach(observer => {
            observer.update()
        })
    }
}
class Observer {
    constructor(name) {
        this.name = name
    }
    update() {
        console.log(this.name, 'update')
    }
}

const subject = new Subject();
const observer1 = new Observer('liu');
const observer2 = new Observer('hao')

subject.add(observer1)
subject.add(observer2)
subject.notify() // liu update hao update